﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Drawing;

namespace Cartoon.Skin
{
    class AbstractSkin:ISkin
    {

        public AbstractSkin()
        {
            this.Load();
            
        }

        protected virtual void Load()
        {
            this.LoadBackGround();
            this.LoadTitleBackGrounds();
        }

        protected ImageSource GetImageSource(System.Drawing.Bitmap bp)
        { 
            return this.GetImageSource(bp, System.Drawing.Imaging.ImageFormat.Png);
        }

        protected ImageSource GetImageSource(System.Drawing.Bitmap bp,System.Drawing.Imaging.ImageFormat f)
        {
            System.Drawing.Bitmap bitmap = bp;
            ImageSourceConverter convert = new ImageSourceConverter();
           
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            bitmap.Save(ms, f);
            BitmapImage myBitmapImage = new BitmapImage();
            

            myBitmapImage.BeginInit(); 
            myBitmapImage.StreamSource = ms; 
            myBitmapImage.EndInit();
 

            FormatConvertedBitmap newFormatedBitmapSource = new FormatConvertedBitmap();

            
            newFormatedBitmapSource.BeginInit(); 
            newFormatedBitmapSource.Source = myBitmapImage;


            newFormatedBitmapSource.DestinationFormat = myBitmapImage.Format;
            newFormatedBitmapSource.EndInit(); 


            return newFormatedBitmapSource;
        }

        protected virtual void LoadBackGround( System.Drawing.Bitmap bp)
        {  
            this._BackGround = this.GetImageSource(bp);
        }

        protected virtual void LoadBackGround()
        {
            this.LoadBackGround(global::Cartoon.Skin.SkinResource.BG_DEFAULT); 
        }

        protected virtual void LoadTitleBackGrounds()
        {
             
            this._CloseMouseOver = this.GetImageSource(global::Cartoon.Skin.SkinResource.close_over, System.Drawing.Imaging.ImageFormat.Png);
            this._CloseNormal = this.GetImageSource(global::Cartoon.Skin.SkinResource.close_normal, System.Drawing.Imaging.ImageFormat.Png);

            this._MinMouseOver = this.GetImageSource(global::Cartoon.Skin.SkinResource.min_over, System.Drawing.Imaging.ImageFormat.Png); 
            this._MinNormal = this.GetImageSource(global::Cartoon.Skin.SkinResource.min_normal, System.Drawing.Imaging.ImageFormat.Png);
            
        }

        #region ISkin 成员

        protected string _SkinName;
        public string SkinName { get { return this._SkinName; } } 

        System.Windows.Media.ImageSource _BackGround;
        public System.Windows.Media.ImageSource BackGround
        {
            get { return this._BackGround; }
        }  

        System.Windows.Media.ImageSource _CloseMouseOver;
        public ImageSource CloseMouseOver
        {
            get { return this._CloseMouseOver; }
        } 

        System.Windows.Media.ImageSource _MinMouseOver;
        public ImageSource MinMouseOver
        {
            get { return this._MinMouseOver; }
        }



        System.Windows.Media.ImageSource _CloseNormal;
        public ImageSource CloseNormal
        {
            get { return this._CloseNormal; }
        }

        System.Windows.Media.ImageSource _MinNormal;
        public ImageSource MinNormal
        {
            get { return this._MinNormal; }
        }

        #endregion
    }
}
